<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/extends/zTree_v3/css/zTreeStyle/zTreeStyle.css"/>
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
    <div style="position: relative;height: 100%;" >
        <div class="ccpui-trees">
                <p class="isShowTree colorSwitch">
                    <span style="float: left;color: #fff">&nbsp;&nbsp;组织机构管理</span>
                    <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
                </p>
                <div style="margin-top: 6px;">
                    <ul class="ccpui-iconTree iconTrees">
                        <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                        <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                        <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                            <input type="text"  style="width: 50%" class="orgZtreeValue">
                    </ul>
                    <ul id="treeSelectUsers" class="ztree ccpui-listZtree"></ul>
                </div>
        </div>
        <div class="layui-form-item btnBox" style="position: absolute;bottom:0px;width:100%;">
            <div style="text-align: center">
                <a lay-submit lay-filter="formUserkeep" class="layui-btn btn-n gs_selconfim">保存</a>
                <a class="layui-btn layui-btn-danger btn-save">取消</a>
                <!--				<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
            </div>
        </div>
    </div>

    <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/public/component.js" type="text/javascript"></script>
    <script src="${ctx}/layui/layui.js"></script>
    <script src="${ctx}/extends/zTree_v3/js/jquery.ztree.all.min.js" type="text/javascript"></script>
    <script src="${ctx}/extends/zTree_v3/js/jquery.ztree.exhide.min.js" type="text/javascript"></script>
    <script>
        layui.config({
            base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index','table', 'layer', 'form', 'laydate', 'totalFilter', 'setter','upload','commons','common'], function() {
                var table = layui.table;
                var layer = layui.layer,totalFilter = layui.totalFilter,form = layui.form,$ = layui.jquery,setter = layui.setter,upload=layui.upload,commons=layui.commons,common=layui.common;
                //选中的左侧角色树的节点ID
                var selectOrgId = "";
                //树状结构
                orgZtree();
                function orgZtree(){
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "sysOrg/list",
                        type: "get",
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function(data) {
                            var zNodes = data.data;
                            var setting = {
                                view: {
                                    showLine: false,
                                    nameIsHTML: true, //允许name支持html
                                    selectedMulti: false
                                },check:{
                                    enable: true,
                                    chkStyle:"radio",
                                    radioType:"all"
                                },
                                edit: {
                                    enable: false,
                                    editNameSelectAll: false
                                },
                                data: {
                                    simpleData: {
                                        enable: true
                                    }
                                },
                                callback: {
                                    onClick: onClickUsers,
                                    beforeCheck:beforeCheck
                                }
                            };
                            $.fn.zTree.init($('#treeSelectUsers'), setting, zNodes);
                            component.fuzzySearch('treeSelectUsers','.orgZtreeValue',null,true); //初始化模糊搜索方法
                        },
                    });
                }
                contHeight();
                function contHeight(){
                    var allW = $(window).width();
                    var allH = $(window).height();
                    $(".ccpui-trees").css("width",allW-20).css("height",allH-78).css("overflow","auto");
                }
                $(window).resize(function(){
                    contHeight();
                })
                $(".btn-save").click(function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
                function beforeCheck(treeId, treeNode){
                        return true;
                }
                function hideRMenu() {
                    if ($("#orgRightMenu")) $("#orgRightMenu").css({"visibility": "hidden"});
                    $("body").unbind("mousedown", onBodyMouseDown);
                }
                function onBodyMouseDown(event){
                    if (!(event.target.id == "orgRightMenu" || $(event.target).parents("#orgRightMenu").length>0)) {
                        $("#orgRightMenu").css({"visibility" : "hidden"});
                    }
                }
                function onClickUsers(event, treeId, treeNode, clickFlag) {
                    selectOrgId = treeNode.orgId;
                    common.tableConditionRender("userListTable","example",{where:{"orgId":treeNode.orgId}},true);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                }
                //展开
                $(".iconTrees .zTree-triangle-d").click(function() {
                    $.fn.zTree.getZTreeObj("treeSelectUsers").expandAll(true);
                });
                //收起
                $(".iconTrees .zTree-triangle-r").click(function() {
                    $.fn.zTree.getZTreeObj("treeSelectUsers").expandAll(false);
                });
                //刷新
                $(".iconTrees .zTree-refresh").click(function() {
                    orgZtree();
                });
                $(document).on("click",".gs_selconfim",function(){
                    var nodeArr=$.fn.zTree.getZTreeObj("treeSelectUsers").getCheckedNodes(true);
                    if(nodeArr.length==0){
                        layer.msg('请选择一个组织');
                    }else{
                        var orgid=nodeArr[0].orgId;
                        layer.confirm('确定移动当前数据吗？', function() {
                            $.ajax({
                                url: serverPath.systemPath + setter.sysLinkPath + "sysUser/move",
                                type: "POST",
                                dataType: 'json',
                                data: {userIds:'${ids}',orgId:orgid},
                                success: function(data) {
                                    if (commons._filterRecord(data)) {
                                        layer.alert(data.msg);
                                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                                        parent.layui.table.reload('userListTable',{page:{curr:1}});
                                    } else {
                                        layer.alert(data.msg);
                                    }
                                }
                            })
                        })
                    }
                })

            });
    </script>
</body>
</html>